package com.bll.imple.sweepstakeAction;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bean.SweepstakeBean;
import com.bll.Action;
import com.dao.Page;
import com.dao.SweepstakeDao;
public class ShowSweepstakeAction implements Action{

	public String execute(HttpServletRequest request,
			HttpServletResponse response) {

		String lujing=request.getParameter("lujing");
		System.out.println("swe:"+lujing);
		SweepstakeDao dao=new SweepstakeDao();
		List<SweepstakeBean> beans=dao.selectAll();
		
		int totalRows=beans.size();
		int rowsPerPage=5;
	    int currentPage=1;
	    int totalPages=Page.computer(totalRows, rowsPerPage);
		if(request.getParameter("currentPage")!=null){
			currentPage=Integer.parseInt(request.getParameter("currentPage"));
			if(currentPage<1){
			
				currentPage=1;
			}else if(currentPage>totalPages){
			
				currentPage=totalPages;
			}
		}
		int currentRows=(currentPage-1)*rowsPerPage;
//		if(request.getParameter("currentRows")!=null){
//			currentRows=Integer.parseInt(request.getParameter("currentRows"));
//		}
		//System.out.println("currenet:"+currentRows);
	    
		request.setAttribute("currentPage", currentPage);
	    request.setAttribute("totalPages", totalPages);
	    List<SweepstakeBean> list=dao.selectPages(currentRows, rowsPerPage);
	    System.out.println("length:"+list.size());
	    request.setAttribute("sweep", list);
		
		//		String lujing=request.getParameter("lujing");
//		System.out.println("swe:"+lujing);
//		SweepstakeDao dao=new SweepstakeDao();
//		List<SweepstakeBean> list=dao.selectAll();
//		request.setAttribute("sweep", list);
		return lujing+"?lujing="+request.getParameter("lujing1");
	}

}
